/**
 * Created by jiaaobo on 16/11/29.
 */
import Util from "util";
import API  from "api";
import constant from "const";

export default{
  name: "bindUser",
  data(){
    return {
      phone : '',
      timeSec : 60,
      code : '',
      isSend : true,
      isSubmit  : false
    }
  },

  mounted: function () {


  },
  methods: {

    onInputCode : function(e){
      if(this.couponCode){
        this.disabled = false;
      }
      else{
        this.disabled = true;
      }
    },
    onBindUser : function(){
      this.isSubmit  = true;
      //获得验证码
      API.biz.updateUserPhone(this.phone,this.code,{hasLoading : true})
        .then((res)=>{
          Util.UI.toast("绑定成功!");
          this.isSubmit  = false;
          window.getRouter().go(-1);
        },(err)=>{
          console.log("err..");
          this.isSubmit  = false;
        })
    },
    sendCode : function () {
      if(!this.phone){
        Util.UI.toast("请输入手机号!");
        return;
      }

      this.isSend = false;
      let interval = setInterval(()=>{
          if(this.timeSec <= 0){
            clearInterval(interval);
            this.timeSec = 60;
            this.isSend = true;
          }
          this.timeSec--;
      }, 1000);

      //获得验证码
      API.biz.baseSendSmsCode(window.USER_INFO.userId,this.phone)
        .then((res)=>{
          Util.UI.toast("发送成功!");
        })

    }
  },
  computed: {},
  components: {

  }
}
